unit dbcComp_Prc;
// Database Comparer VCL v.3.0
// Copyright (C) 1998-2006, by Boris Loboda
// www.CleverComponents.com
{$I Comparer.INC}

// compare procedures
//
// History:
// 20.05.2004 (BL)
//  - Fix to use procedure dependencies on script-comparison.
// 10.06.2004 (BL)
// - Update description of procedure params - if param-list changed
// 25.02.2005 (BL)
// - Fix double alter for procedure-body.

interface

Uses Classes, Dialogs, dbcComp_Tbl, dbcSQL_Exec,
     dbcClasses, dbcTypes;

type
  TPrcData = class(TDbObj)
  protected
    fRestoreBody: Boolean; // need restore procedure body after clear
    function IB_Def(Body: String): String;        // InterBase definition
    function SAW_Def(Body: String): String;       // Sybase    definition
    function MSSQL_Def(Body: String): String;     // MSSQL     definition
    function Oracle_Def(Body: String): String;    // Oracle    definition
    function PG_Def(Body: String): String;        // PosgreSQL definition
    function MySQL_Def(Body: String): String;     // MySQL     definition
    procedure SetRestoreBody(aValue: Boolean);
    function GetCaption(): String; override;
    function GetHasReturnsTable(): Boolean;
    function GetObjKeyDef(): String; override;
  public
    // source body (Target-DB) - After AS [...]
    SourceBody: String;
    Params: TStringList;  // input  params - field names & TFldData's
    Returns: TStringList; // return params - field names & TFldData's
    ReturnsTable: Boolean;
    SelectProc: Boolean;
    Number: Integer;
    Grant: TGrantPrivilegeSet;
    Func: Boolean; // function: for SQLAnywere / Oracle
    ObjFile, LinkSymbol: String;
    Language: String;
    Volatile: String; // immutable / stable / volatile
    ProcStrict: Boolean;
    RetValue: String; // PgSQL
    RetSetOf: Boolean;  // PgSQL
//    RetVoid: Boolean;   // PgSQL
//    RetRecord: Boolean; // PgSQL
    ProcOption: String;
    ModifiesSqlData: Boolean; // MS SQL
    DynamicResultSets: Integer;
    Deterministic: Boolean;
    Exportable: Boolean;
    ParameterStyle: String;
    ExternalName: String;
    MySqlOptions: TMySqlProcOptionsSet;
    property RestoreBody: Boolean read fRestoreBody write SetRestoreBody;
    property HasReturnsTable: Boolean read GetHasReturnsTable;
    function Def(): String; override; // PROCEDURE <name> ....
    function DropDef(): String; override;
    function AlterDef(): String; override;
    function ParamDef(ReturnsDef: Boolean = True): String; // (Param1, Param2...) returns (...)
    function EmptyBody(): String; // begin exit; end
    function EmptyDef(): String;
    function AlterEmptyDef(): String;
    // Empty body and deactivate UseIn-list dependencies
    procedure AssignEmptyBody(GenSQL: Boolean = True);
    procedure ClearParams();
    procedure DoBeforeCreate(); override;
    procedure DoBeforeDrop(); override;
    constructor Create(aObjs: TCustomObjs);
    destructor Destroy(); override;
    function CreateDef(): string; override;
  end;

  // Member procedure / function (Oracle)
  TMemberPrcData = class(TPrcData)
  public
    TypeName: String;
    Params : String;
    ProcDirective: TTypeDirective;
    function Def(): String; override;
    constructor Create(aObjs: TCustomObjs);
    destructor Destroy; override;
  end;

  // OPERATOR (PostgreSQL)
  TOprData = class(TDbObj)
  protected
    function GetCaption(): String; override;
    function GetObjKeyDef(): String; override;
  public
    Proc: String;
    LeftArg, RightArg: String;
    Commutator, Negator: String;
    Restrict, Join: String;
    Hashes, Merges: Boolean;
    Sort1, Sort2: String;
    LtCmp, GtCmp: String;
    constructor Create(aObjs: TCustomObjs);
    function Def(): String; override;
    function ParamDef(): String;
    function DropDef(): String; override;
  end;

  TOpcData = class;

  TOpcOprData = class
  protected
    fOwner: TOpcData;
  public
    Number: integer;
    ObjName: string;
    lArg, rArg: string;
    ReCheck: Boolean;
    constructor Create(aOwner: TOpcData);
    function Def(): String;
    function ParamDef(): String;
    function ObjKeyDef(): String;
  end;

  TOpcFncData = class
  protected
    fOwner: TOpcData;
  public
    Number: integer;
    ObjName: string;
    Params: TStrings;
    constructor Create(aOwner: TOpcData);
    destructor Destroy; override;
    function Def(): String;
    function ParamDef(): String;
    function ObjKeyDef(): String;
  end;

  // OPERATOR CLASS (PostgreSQL)
  TOpcData = class(TDbObj)
  protected
    function GetCaption(): String; override;
    function GetObjKeyDef(): String; override;
  public
    DefOpClass: Boolean;
    ForType: String;
    IdxMethod: String;
    Opr, Fnc: TStrings;
    Storage: String;
    constructor Create(aObjs: TCustomObjs);
    destructor Destroy; override;
    function Def(): String; override;
    function DropDef(): String; override;
  end;

procedure GenScriptProcCreate(dbc: TCustomDBComparer);
procedure GenScriptProcAlter(dbc: TCustomDBComparer);
procedure GenScriptProcDrop(dbc: TCustomDBComparer);

procedure GenScriptOprCreate(dbc: TCustomDBComparer);
procedure GenScriptOprAlter(dbc: TCustomDBComparer);
procedure GenScriptOprDrop(dbc: TCustomDBComparer);

procedure GenScriptOpcCreate(dbc: TCustomDBComparer);
procedure GenScriptOpcAlter(dbc: TCustomDBComparer);
procedure GenScriptOpcDrop(dbc: TCustomDBComparer);

implementation

//The full source code is available on purchasing the product

end.
